﻿Public Class MASGRPOPER
    Private GRPID As Integer = Nothing
    Private CODE As String = Nothing
    Private GRPNAME As String = Nothing
    Private STATUS = Nothing
    Private SelectMasgrpoper = "SELECT `grpid`,`code` as 'รหัสกลุ่ม',`grpname` as 'ชื่อกลุ่มหัตถการ',`status` as 'สถานะการเปิดใช้งาน' FROM masgrpoper "
    Dim connect As CONDB = CONDB.NewConnection
    Property SelectMasgrpoper_() As String
        Get
            Return SelectMasgrpoper
        End Get
        Set(value As String)

        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property GRPNAME_() As String
        Get
            Return GRPNAME
        End Get
        Set(value As String)
            GRPNAME = value
        End Set
    End Property

    Property CODE_() As String
        Get
            Return CODE
        End Get
        Set(value As String)
            CODE = value
        End Set
    End Property

    Property GRPID_() As Integer
        Get
            Return GRPID
        End Get
        Set(value As Integer)
            GRPID = value
        End Set
    End Property

    Public Sub insertMasgrpoperData()
        If TypeOf GRPNAME Is String Then
            If connect.GetTable("SELECT `grpname` FROM masgrpoper WHERE  `grpname` = '" & GRPNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    Dim sql As String
                    sql = "INSERT INTO masgrpoper"
                    sql += "(`grpname`,`code`,`STATUS`)"
                    sql += "VALUES ("
                    sql += "'" & GRPNAME & "',"
                    sql += "'" & CODE & "',"
                    sql += "'" & STATUS & "')"
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
    Public Sub editMasgrpoperData()
        If TypeOf GRPNAME Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE masgrpoper SET"
                sql += "`grpname` = '" & GRPNAME & "',"
                sql += "`code` = '" & CODE & "',"
                sql += "`STATUS` = '" & STATUS & "' "
                sql += "WHERE `grpid` = '" & GRPID & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
